<?php  
import ('miho.iterator.*');
/**
* 
*/
class RouterMap implements ArrayAccess
{
  
  protected $_routes;
  public function getRoutes(){
    return $this->_routes;
  }
      
  public function __construct()
  {
    $this->clear();
  }
  
  public function clear(){
    $this->_routes = array();
  }
  
  public function addRoute(IRoute $route){
    if(!isset($this->_routes[$route->getName()])){
      $this->_routes[$route->getName()] = $route;
    }
    
    return $this;
  }
  
  public function getSize(){
    return sizeof($this->_map);
  }
  
  public function getRoute($index){
    return isset($this->_routes[$index]) ? $this->_routes[$index] : null;
  }
  
  // ARRAY ACCESS
  public function offsetSet($offset, $value) {
    throw new Error('Use addRoute');
  }
  public function offsetExists($offset) {
    return isset($this->_routes[$offset]);
  }
  public function offsetUnset($offset) {
    throw new Error('Use remove route');
  }
  public function offsetGet($offset) {
    return $this->getRoute($offset);
  }
  
}